<html>
<head><meta charset="utf-8"><title>MIR without places · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html">MIR without places</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233997838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/233997838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#233997838">(Apr 10 2021 at 23:26)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> The rules I originally gave are about the syntactic safety properties that are applied during and shortly after MIR creation. When I say "safe" and "unsafe" in those rules, I mean "you need an <code>unsafe</code> block". After applying those rules, you end up with something that doesn't directly need places, but the place operations are translated to relevant pointer operations:</p>
<ul>
<li><code>*ptr</code> and <code>addr_of!(ptr)</code> don't themselves require any pointer operations, since they are eliminated by the translation</li>
<li><code>place.field</code> requires an operation that I have written <code>ptr.field()</code> and can be meta-circularly defined as <code>&amp;raw (*ptr).field</code>, or <code>ptr.add(offset_of!(Foo, field))</code>. Assuming we don't let it wrap, this operation is unsafe to be applied to a pointer which was not derived from a reference, but the safety rules ensure that we have an unsafe block around the operation.</li>
<li>Reading a place, <code>{place}</code> translates to <code>ptr::read(place_ptr)</code>.</li>
<li>Writing a place, <code>place = expr</code> translates to <code>ptr::drop_in_place(place_ptr); ptr::write(place_ptr, expr)</code>.</li>
</ul>
<p>What I mean by the final paragraph is that I think the safety checking and dynamic semantics should be <em>equivalent</em> to this model, whether or not places exist in MIR. Are there any specific aspects of the model where you think it gives the wrong answer?</p>



<a name="233998342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/233998342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#233998342">(Apr 10 2021 at 23:34)</a>:</h4>
<blockquote>
<p>MIR as a language inherently has places; it seems very strange to try to shoehorn a non-place semantics onto such a language. That just leads to confusion.</p>
</blockquote>
<p>I rather think it leads to simplification. Is there a reason places need to be magic that can't be simulated with pointers and/or references? In what way do they differ?</p>



<a name="233999829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/233999829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#233999829">(Apr 11 2021 at 00:00)</a>:</h4>
<p>That said, I do see some inadequacies of the model around certain edge cases, particularly involving packed struct references and writes.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[repr(packed)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Packed</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">5</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="kt">u32</span> <span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="nc">Packed</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">Foo</span><span class="p">;</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">p</span>: <span class="nc">Packed</span><span class="p">;</span><span class="w"> </span><span class="c1">// pretend these are initialized</span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">b</span><span class="p">.</span><span class="n">b</span><span class="p">;</span><span class="w"> </span><span class="c1">// (1) should this be safe?</span>
<span class="kd">let</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">a</span><span class="p">;</span><span class="w"> </span><span class="c1">// (2) should this be safe?</span>
<span class="n">p</span><span class="p">.</span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="mi">5</span><span class="p">];</span><span class="w"> </span><span class="c1">// (3) should this be safe?</span>
<span class="n">p</span><span class="p">.</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="c1">// (4) should this be safe?</span>
</code></pre></div>
<p>One can imagine doing an analysis with (1) to see that since <code>&amp;raw x.b.b = x + 8</code>, and <code>x</code> is aligned, <code>x.b.b</code> is also aligned and so (1) should be (syntactically) safe. To support this, the compositional semantics are insufficient, unless we add offsets: we have to remember that <code>x.b</code> is an unaligned place with offset 5, so <code>x.b.b</code> is a place with offset 8, which is aligned because the type's alignment is 4, and so <code>{x.b.b}</code> is a safe operation. (Then again, this is maybe exposing too much layout detail to the safety checker. The approach taken in the original proposal is more conservative and assumes that a place is unaligned if there are any packed structs involved at all.)</p>
<p>For (2) and (3), currently it is legal to read and write from an unaligned place, but not take a reference and read from that. To support this, one would have to keep track of whether a place is aligned or (potentially) unaligned for its type, even if it's a pointer place, so that the MIR generates an aligned/unaligned load or store as appropriate.</p>



<a name="234030310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234030310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234030310">(Apr 11 2021 at 09:20)</a>:</h4>
<blockquote>
<p>The rules I originally gave are about the syntactic safety properties that are applied during and shortly after MIR creation. </p>
</blockquote>
<p>Oh I see. Those rules were not the main subject of this thread so I thought you meant something else.<br>
This thread [where these messages were originally posted; I moved them] is all about changing the <em>dynamic</em> safety rules (i.e., the UB rules).</p>



<a name="234030358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234030358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234030358">(Apr 11 2021 at 09:21)</a>:</h4>
<p>I get the feeling you are proposing a rather radical change of MIR away from being a place-based language -- that's a fair proposal but entirely off-topic for this thread I think. So I created a new Zulip topic for this.</p>



<a name="234030380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234030380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234030380">(Apr 11 2021 at 09:21)</a>:</h4>
<blockquote>
<p>What I mean by the final paragraph is that I think the safety checking and dynamic semantics should be equivalent to this model, whether or not places exist in MIR. Are there any specific aspects of the model where you think it gives the wrong answer?</p>
</blockquote>
<p>Dynamic and static semantics are never going to be <em>equivalent</em>, I don't even know what that is supposed to mean...<br>
At some point during this thread we started talking entirely past each other and now I don't feel like this discussion even still has a clear goal or topic.^^</p>



<a name="234031137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234031137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234031137">(Apr 11 2021 at 09:34)</a>:</h4>
<p>Of course a place-based language can always be translated to one without places (and the LLVM backend does exactly that). But since surface Rust has place-based syntax, MIR has place-based syntax, and Miri has place-based dynamic semantics (which is pretty much unavoidable given MIR being place-based) -- why would you want to do that?</p>
<p>if you want to just change the MIR <em>semantics</em> away from places but keep places in the <em>syntax</em>, you'll need some really good arguments since that mismatch will be really painful... basically at this point you are proposing to add <em>another language</em> to the stack, "MIR_noplace", and to define the semantics of MIR by translation to MIR_noplace. I don't think that is a good idea, adding a whole new language is a major increase in complexity and in no way justified by the tiny gain of getting rid of places. It is certainly not how Miri works, so this change will also make it <em>harder</em> to relate a MIR spec with Miri.</p>
<p>The static semantics of MIR is most certainly not going to move away from places any time soon (that would affect like half of rustc). So your proposal can only be about the dynamic semantics... but then you said it is about the <em>static</em> safety checks... I am still very confused about what it even is you are proposing to do. What is even the problem you are trying to solve by getting rid of places? That proposal came entirely out of the blue in the middle of an unrelated discussion, as far as I am concerned.^^ (I moved it to a new thread.)</p>



<a name="234031335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234031335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234031335">(Apr 11 2021 at 09:38)</a>:</h4>
<blockquote>
<p>Is there a reason places need to be magic that can't be simulated with pointers and/or references? In what way do they differ?</p>
</blockquote>
<p>Places aren't magic. They are also clearly distinct from (pointer) values, as is apparent even in the Rust syntax. You cannot syntactically use a value where a place is required.</p>



<a name="234031441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234031441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234031441">(Apr 11 2021 at 09:40)</a>:</h4>
<p>See e.g. <a href="https://robbertkrebbers.nl/thesis.html">this PhD thesis</a> for a formal semantics for C that works directly with places.<br>
No magic. And this way you get a nice and compositional semantics that follows the syntactic structure of the language. So IMO it is obviously the right way to give semantics to a language with places.</p>



<a name="234031792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234031792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234031792">(Apr 11 2021 at 09:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234030380">said</a>:</p>
<blockquote>
<blockquote>
<p>What I mean by the final paragraph is that I think the safety checking and dynamic semantics should be equivalent to this model, whether or not places exist in MIR. Are there any specific aspects of the model where you think it gives the wrong answer?</p>
</blockquote>
<p>Dynamic and static semantics are never going to be <em>equivalent</em>, I don't even know what that is supposed to mean...<br>
At some point during this thread we started talking entirely past each other and now I don't feel like this discussion even still has a clear goal or topic.^^</p>
</blockquote>
<p>That's not what is being equated here. I mean that the safety checking should be equivalent to the safety checks in the static (MIR lowering) part of the model, and the dynamic semantics should be equivalent to the dynamic semantics (behavior of the place pointer operations) in the model</p>



<a name="234031976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234031976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234031976">(Apr 11 2021 at 09:50)</a>:</h4>
<blockquote>
<p>Places aren't magic. They are also clearly distinct from (pointer) values, as is apparent even in the Rust syntax. You cannot syntactically use a value where a place is required.</p>
</blockquote>
<p>We're definitely talking past each other. In what way is a place not a pointer? I don't mean syntactically, obviously the stars and ampersands move around. This is similar to the question of how C++ references differ from pointers; to a first approximation they are just a trivial syntactic transformation. I'm trying to get at what <em>other</em> differences there are, that make it impossible to desugar places into pointers as I've described.</p>



<a name="234031992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234031992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234031992">(Apr 11 2021 at 09:50)</a>:</h4>
<p>I am sure you can devise a sufficiently complicated translation that accurately captures place semantics in a target language without places. it's not going to be entirely trivial; places in Miri are denoted by a pointer <em>and an alignment</em> to properly account for field accesses to packed structs in a compositional way.<br>
But that is a trivial statement, you can compile away almost anything.^^ What is wholly unclear to me is what you'd gain by doing this. all of the MIR-based static analyses, including unsafety checking, work on places -- and they have to unless you want to change like half of rustc. likewise for Miri, it works on places. and places aren't really complicated either, they are just a separate syntactic class with its own denotation  and reduction relation.</p>



<a name="234032029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032029">(Apr 11 2021 at 09:51)</a>:</h4>
<blockquote>
<p>In what way is a place not a pointer? </p>
</blockquote>
<p>a place isn't a value. we don't even seem to have compatible ontologies here...</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">enum</span> <span class="nc">Value</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">Pointer</span><span class="p">(</span><span class="n">Pointer</span><span class="p">),</span><span class="w"></span>
<span class="w">  </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Place</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">pointer</span>: <span class="nc">Pointer</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">alignment</span>: <span class="nc">Align</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="234032082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032082">(Apr 11 2021 at 09:52)</a>:</h4>
<p>but even if the <code>alignment</code> field wouldn't exist, there'd still be a very clear different between <code>Value</code> and <code>Place</code> here</p>



<a name="234032106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032106">(Apr 11 2021 at 09:52)</a>:</h4>
<blockquote>
<p>places in Miri are denoted by a pointer and an alignment to properly account for field accesses to packed structs in a compositional way.</p>
</blockquote>
<p>Okay, now we're getting somewhere. I mention that alignment needs to get added into the model to handle packed places in <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/233999829">this</a> addendum, so I think we are converging</p>



<a name="234032107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032107">(Apr 11 2021 at 09:52)</a>:</h4>
<p>"pointer" is not a syntactic class in rustc. so if by "is a place a pointer" you mean "are these two words for the same thing", the answer is definitely no -- the question isn't even well-typed.</p>



<a name="234032122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032122">(Apr 11 2021 at 09:53)</a>:</h4>
<p>the syntactic class here is "value, of pointer type"</p>



<a name="234032131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032131">(Apr 11 2021 at 09:53)</a>:</h4>
<p>that's not a syntactic class though</p>



<a name="234032139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032139">(Apr 11 2021 at 09:53)</a>:</h4>
<p>"value" then</p>



<a name="234032142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032142">(Apr 11 2021 at 09:53)</a>:</h4>
<p>the syntax just has "values" and "places" (and a few other things like "types")</p>



<a name="234032207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032207">(Apr 11 2021 at 09:54)</a>:</h4>
<p>and "place" as a syntactic class is clearly distinct from "value" as a syntactic class since "5 = x" is ill-formed syntax</p>



<a name="234032212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032212">(Apr 11 2021 at 09:54)</a>:</h4>
<p>No, it's not 5 = x, it's <code>*5 = x</code></p>



<a name="234032227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032227">(Apr 11 2021 at 09:54)</a>:</h4>
<p>the "value" in question is the address of the place</p>



<a name="234032243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032243">(Apr 11 2021 at 09:55)</a>:</h4>
<p>if we ignore alignment, a place expression <em>denotes</em> a "place result" (<em>argh</em> why did we call the other class 'value' so we cannot use standard terminology here). which is, semantically, a pointer.</p>



<a name="234032259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032259">(Apr 11 2021 at 09:55)</a>:</h4>
<p>yes!</p>



<a name="234032267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032267">(Apr 11 2021 at 09:55)</a>:</h4>
<p>a value expression <em>denotes</em> a "value result" or "value", which is an element of <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md">an enum with many variants</a></p>



<a name="234032324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032324">(Apr 11 2021 at 09:56)</a>:</h4>
<p>Okay, so we have a bit more syntactic type safety with this definition</p>



<a name="234032334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032334">(Apr 11 2021 at 09:56)</a>:</h4>
<p>there are typing rules for places and typing rules for values</p>



<a name="234032340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032340">(Apr 11 2021 at 09:56)</a>:</h4>
<p>etc pp</p>



<a name="234032349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032349">(Apr 11 2021 at 09:56)</a>:</h4>
<p>But the typing rules for places should be a subset of the typing rules for values</p>



<a name="234032368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032368">(Apr 11 2021 at 09:57)</a>:</h4>
<p><code>&amp;</code> turns a place into a value; denoting a <code>Value::Pointer</code>.<br>
<code>*</code> does the opposite (causing UB if the value is not a <code>Value::Pointer</code>; this is prevented by the type system).</p>



<a name="234032373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032373">(Apr 11 2021 at 09:57)</a>:</h4>
<p>specifically, the typing rules for values of the form <code>ptr</code> and <code>ptr.add(offset_of!(Foo, field))</code></p>



<a name="234032375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032375">(Apr 11 2021 at 09:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234032349">said</a>:</p>
<blockquote>
<p>But the typing rules for places should be a subset of the typing rules for values</p>
</blockquote>
<p>no? they are just different</p>



<a name="234032379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032379">(Apr 11 2021 at 09:57)</a>:</h4>
<p>I cant even typecheck your statement</p>



<a name="234032420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032420">(Apr 11 2021 at 09:58)</a>:</h4>
<p>place typing and value typing apply to distinct syntactic classes</p>



<a name="234032437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032437">(Apr 11 2021 at 09:58)</a>:</h4>
<p>There is an operation that adds a number to a pointer. Rust has annoying syntax for it, C would call it <code>&amp;ptr-&gt;field</code></p>



<a name="234032438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032438">(Apr 11 2021 at 09:58)</a>:</h4>
<p>as in: <code>place_typing: place_expr → type → Prop</code>, <code>value_typing: value_expr → type → Prop</code></p>



<a name="234032443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032443">(Apr 11 2021 at 09:58)</a>:</h4>
<p>That operation can be defined as a function from values of pointer type to values of pointer type</p>



<a name="234032445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032445">(Apr 11 2021 at 09:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234032437">said</a>:</p>
<blockquote>
<p>There is an operation that adds a number to a pointer. Rust has annoying syntax for it, C would call it <code>&amp;ptr-&gt;field</code></p>
</blockquote>
<p>on the C side what you just wrote are <em>three</em> operations</p>



<a name="234032455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032455">(Apr 11 2021 at 09:59)</a>:</h4>
<p>so type system and dynamic semantics treat that compositonally, of course</p>



<a name="234032456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032456">(Apr 11 2021 at 09:59)</a>:</h4>
<p>even though the common syntax for it looks like places</p>



<a name="234032459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032459">(Apr 11 2021 at 09:59)</a>:</h4>
<p>I mean <code>ptr + 8</code></p>



<a name="234032464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032464">(Apr 11 2021 at 09:59)</a>:</h4>
<p>where <code>8</code> is the offset of <code>field</code></p>



<a name="234032465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032465">(Apr 11 2021 at 09:59)</a>:</h4>
<p>that's not even the same thing in C</p>



<a name="234032468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032468">(Apr 11 2021 at 09:59)</a>:</h4>
<p>like, the UB rules are very different</p>



<a name="234032471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032471">(Apr 11 2021 at 09:59)</a>:</h4>
<p>it's just annoying to talk about this because the common syntax for it brings in all this place stuff</p>



<a name="234032515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032515">(Apr 11 2021 at 10:00)</a>:</h4>
<p>(ptr arithmetic is allowed inside arrays but not for fields)</p>



<a name="234032546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032546">(Apr 11 2021 at 10:00)</a>:</h4>
<p>Aah, I mean <code>&amp;ptr-&gt;field</code> <em>as one operation</em></p>



<a name="234032553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032553">(Apr 11 2021 at 10:00)</a>:</h4>
<p>just pretend that's a primitive</p>



<a name="234032559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032559">(Apr 11 2021 at 10:00)</a>:</h4>
<p>that's not a thing</p>



<a name="234032566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032566">(Apr 11 2021 at 10:00)</a>:</h4>
<p>but it isn't?^^</p>



<a name="234032573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032573">(Apr 11 2021 at 10:00)</a>:</h4>
<p>are we talking about C, Rust, or your fantasy language? ;)</p>



<a name="234032578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032578">(Apr 11 2021 at 10:00)</a>:</h4>
<p>I'm desugaring all place ops into that operation</p>



<a name="234032594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032594">(Apr 11 2021 at 10:01)</a>:</h4>
<p>but what problem is that solving?</p>



<a name="234032595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032595">(Apr 11 2021 at 10:01)</a>:</h4>
<p>It exists in rust, it's <code>std::ptr::add</code></p>



<a name="234032600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032600">(Apr 11 2021 at 10:01)</a>:</h4>
<p>that's not a primitive</p>



<a name="234032601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032601">(Apr 11 2021 at 10:01)</a>:</h4>
<p>it's a function</p>



<a name="234032602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032602">(Apr 11 2021 at 10:01)</a>:</h4>
<p>it's an intrinsic</p>



<a name="234032652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032652">(Apr 11 2021 at 10:02)</a>:</h4>
<p>MIR could totally just have a primitive operation for this, just like <code>set_discriminant</code></p>



<a name="234032662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032662">(Apr 11 2021 at 10:02)</a>:</h4>
<p>I mean, sure...</p>



<a name="234032664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032664">(Apr 11 2021 at 10:02)</a>:</h4>
<p>(no idea where you are going)</p>



<a name="234032668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032668">(Apr 11 2021 at 10:02)</a>:</h4>
<p>in a sense, it already does, these are the <code>Projection</code>s, but the place stuff is confusing matters</p>



<a name="234032713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032713">(Apr 11 2021 at 10:03)</a>:</h4>
<p>could you maybe make a problem statement? you want to desugar all place ops. I already conceded that that is possible -- this was never contentious. the LLVM backend does it. but what problem do you want to solve?</p>



<a name="234032714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032714">(Apr 11 2021 at 10:03)</a>:</h4>
<p>My point is that the safety of these place ops should be the same as the safety of computing <code>ptr + 8 + 3 * n + 2</code></p>



<a name="234032725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032725">(Apr 11 2021 at 10:03)</a>:</h4>
<p>except that you can't directly write it like that for reasons</p>



<a name="234032729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032729">(Apr 11 2021 at 10:03)</a>:</h4>
<p>but the compiler's basically doing that</p>



<a name="234032789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032789">(Apr 11 2021 at 10:04)</a>:</h4>
<p>we have a way to give semantics to MIR that is fully compositional, by basically structural induction on the syntax, accounting for the fact that we have value expressions and place expressions. I encourage you to read the Miri core engine source code, it helped me a lot to understand how to give such semantics to MIR.<br>
so, what's wrong with this semantics that you want to give a different one?</p>



<a name="234032790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032790">(Apr 11 2021 at 10:04)</a>:</h4>
<p>I want to define what place ops are safe (both syntactically and dynamically), particularly when <code>addr_of</code> is involved</p>



<a name="234032823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032823">(Apr 11 2021 at 10:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234032790">said</a>:</p>
<blockquote>
<p>I want to define what place ops are safe (both syntactically and dynamically), particularly when <code>addr_of</code> is involved</p>
</blockquote>
<p>you dont need to rearrange the entire operational semantics for that^^</p>



<a name="234032835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032835">(Apr 11 2021 at 10:05)</a>:</h4>
<p>I think my model is already quite close to Miri's</p>



<a name="234032844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032844">(Apr 11 2021 at 10:05)</a>:</h4>
<p>I'm not overhauling anything like you seem to think</p>



<a name="234032852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032852">(Apr 11 2021 at 10:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234032835">said</a>:</p>
<blockquote>
<p>I think my model is already quite close to Miri's</p>
</blockquote>
<p>Miri fundamentally distinguishes between places and values though...</p>



<a name="234032858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032858">(Apr 11 2021 at 10:06)</a>:</h4>
<p>That's fine</p>



<a name="234032906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032906">(Apr 11 2021 at 10:06)</a>:</h4>
<p>it sounded earlier like you wanted to get rid of that via desugaring to another language...</p>



<a name="234032916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032916">(Apr 11 2021 at 10:06)</a>:</h4>
<p>I want to make "place results" recognizable as a subset of "value results" (with alignment info)</p>



<a name="234032946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032946">(Apr 11 2021 at 10:07)</a>:</h4>
<p>hm, I dont think "subset" is the right term here</p>



<a name="234032957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032957">(Apr 11 2021 at 10:07)</a>:</h4>
<p>(certainly not in Miri due to alignment)</p>



<a name="234032959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032959">(Apr 11 2021 at 10:07)</a>:</h4>
<p>it ignores the type structure</p>



<a name="234032968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032968">(Apr 11 2021 at 10:07)</a>:</h4>
<p>as set theorist would say "subset" but as a type theorist I cannot agree :P</p>



<a name="234032972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032972">(Apr 11 2021 at 10:07)</a>:</h4>
<p>A place result is a pointer plus an offset, yes?</p>



<a name="234032976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032976">(Apr 11 2021 at 10:07)</a>:</h4>
<p><em>pointers</em> are a subset of values</p>



<a name="234032979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032979">(Apr 11 2021 at 10:07)</a>:</h4>
<p>and places are "newtyped pointers"</p>



<a name="234032982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032982">(Apr 11 2021 at 10:07)</a>:</h4>
<p>but "newtyped" matters</p>



<a name="234032983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234032983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234032983">(Apr 11 2021 at 10:07)</a>:</h4>
<p>Take the first projection, then it's a subset ^^</p>



<a name="234033026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033026">(Apr 11 2021 at 10:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234032972">said</a>:</p>
<blockquote>
<p>A place result is a pointer plus an offset, yes?</p>
</blockquote>
<p>no, its just a pointer (plus an alignment)</p>



<a name="234033039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033039">(Apr 11 2021 at 10:08)</a>:</h4>
<p>but as I said, the newtype matters</p>



<a name="234033041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033041">(Apr 11 2021 at 10:08)</a>:</h4>
<p>Er, I meant alignment</p>



<a name="234033075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033075">(Apr 11 2021 at 10:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234032979">said</a>:</p>
<blockquote>
<p>and places are "newtyped pointers"</p>
</blockquote>
<p>Great, I can work with that. So <code>*ptr</code> is the newtype constructor, and <code>addr_of!</code> is the newtype projection</p>



<a name="234033084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033084">(Apr 11 2021 at 10:09)</a>:</h4>
<p>and neither one has to do anything else fancy</p>



<a name="234033092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033092">(Apr 11 2021 at 10:09)</a>:</h4>
<p><code>addr_of!</code> is the newtype projection <em>followed by the value injection</em></p>



<a name="234033094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033094">(Apr 11 2021 at 10:09)</a>:</h4>
<p>no no</p>



<a name="234033099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033099">(Apr 11 2021 at 10:09)</a>:</h4>
<p>er wait</p>



<a name="234033102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033102">(Apr 11 2021 at 10:09)</a>:</h4>
<p><code>addr_of!</code> basically has type <code>Place&lt;T&gt; → Value&lt;*const T&gt;</code></p>



<a name="234033103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033103">(Apr 11 2021 at 10:09)</a>:</h4>
<p>which injection?</p>



<a name="234033108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033108">(Apr 11 2021 at 10:09)</a>:</h4>
<p>It's throwing away the alignment you mean</p>



<a name="234033112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033112">(Apr 11 2021 at 10:10)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">enum</span> <span class="nc">Value</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">Pointer</span><span class="p">(</span><span class="n">Pointer</span><span class="p">),</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><code>Value::Pointer</code> is the injection</p>



<a name="234033140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033140">(Apr 11 2021 at 10:10)</a>:</h4>
<p>"enum constructor"</p>



<a name="234033158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033158">(Apr 11 2021 at 10:10)</a>:</h4>
<p>Sure</p>



<a name="234033179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033179">(Apr 11 2021 at 10:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234033102">said</a>:</p>
<blockquote>
<p><code>addr_of!</code> basically has type <code>Place&lt;T&gt; → Value&lt;*const T&gt;</code></p>
</blockquote>
<p>^</p>



<a name="234033182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033182">(Apr 11 2021 at 10:10)</a>:</h4>
<p>But the key point is that the pointer and whatever provenance it has has no bearing here</p>



<a name="234033189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033189">(Apr 11 2021 at 10:10)</a>:</h4>
<p>the rest is type tetris</p>



<a name="234033190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033190">(Apr 11 2021 at 10:10)</a>:</h4>
<p>thinking of places and values as being "distinctly typed" is what made it really click for me, FWIW</p>



<a name="234033202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033202">(Apr 11 2021 at 10:11)</a>:</h4>
<p>I agree that they are newtyped</p>



<a name="234033211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033211">(Apr 11 2021 at 10:11)</a>:</h4>
<p>so do we agree on this?<br>
"<code>addr_of!</code> basically has type <code>Place&lt;T&gt; → Value&lt;*const T&gt;</code>"</p>



<a name="234033219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033219">(Apr 11 2021 at 10:11)</a>:</h4>
<p>Yes</p>



<a name="234033227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033227">(Apr 11 2021 at 10:11)</a>:</h4>
<p>It moreover should be a very trivial function</p>



<a name="234033271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033271">(Apr 11 2021 at 10:12)</a>:</h4>
<p>throw away alginment information, inject to <code>Value</code></p>



<a name="234033272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033272">(Apr 11 2021 at 10:12)</a>:</h4>
<p><em>unlike</em> <code>place2value</code></p>



<a name="234033280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033280">(Apr 11 2021 at 10:12)</a>:</h4>
<p>I can show you the code in Miri^^</p>



<a name="234033293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033293">(Apr 11 2021 at 10:12)</a>:</h4>
<p><code>place2value</code> has type <code>Place&lt;T&gt; → Value&lt;T&gt;</code>. it does a "typed load" from memory. indeed it is non-trivial.</p>



<a name="234033311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033311">(Apr 11 2021 at 10:13)</a>:</h4>
<p>Similarly, <code>*ptr</code> is also a simple operation</p>



<a name="234033321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033321">(Apr 11 2021 at 10:13)</a>:</h4>
<p>it should have type <code>Value&lt;*const T&gt; -&gt; Place&lt;T&gt;</code></p>



<a name="234033329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033329">(Apr 11 2021 at 10:13)</a>:</h4>
<p>and it manufactures alignment information from the alignment of T I guess</p>



<a name="234033368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033368">(Apr 11 2021 at 10:14)</a>:</h4>
<p>yes (or any other ptr type).<br>
it is less simple though at least under our current UB rules -- it has to check if the ptr is dereferencable and aligned. (yes I know you want to change that.)</p>



<a name="234033383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033383">(Apr 11 2021 at 10:14)</a>:</h4>
<p>Right, that's what I'm getting at here</p>



<a name="234033386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033386">(Apr 11 2021 at 10:14)</a>:</h4>
<p>I think even in C it might check for being dereferencable? not sure. but yes we could change this.</p>



<a name="234033404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033404">(Apr 11 2021 at 10:15)</a>:</h4>
<p>I even proposed exactly that <a href="#narrow/stream/213817-t-lang/topic/Alignment.20and.20raw.20pointer.20deref/near/233450446">here</a></p>



<a name="234033405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033405">(Apr 11 2021 at 10:15)</a>:</h4>
<p>It doesn't need to be dereferenceable to do its job (produce a place result)</p>



<a name="234033420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033420">(Apr 11 2021 at 10:15)</a>:</h4>
<p>Not clear whether it has to be aligned to work</p>



<a name="234033439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033439">(Apr 11 2021 at 10:15)</a>:</h4>
<p>I guess if it's an unaligned pointer it just produces an unaligned place</p>



<a name="234033442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033442">(Apr 11 2021 at 10:15)</a>:</h4>
<p>which should be fine</p>



<a name="234033444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033444">(Apr 11 2021 at 10:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234033405">said</a>:</p>
<blockquote>
<p>It doesn't need to be dereferenceable to do its job (produce a place result)</p>
</blockquote>
<p>not sure what you mean... if you mean "we could remove that UB and still get a reasonably implementable semantics", then yes.</p>



<a name="234033487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033487">(Apr 11 2021 at 10:16)</a>:</h4>
<p>yes that's what I mean</p>



<a name="234033497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033497">(Apr 11 2021 at 10:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234033439">said</a>:</p>
<blockquote>
<p>I guess if it's an unaligned pointer it just produces an unaligned place</p>
</blockquote>
<p>yeah, and you'd get UB on place2value as the alignment recorded in the place wouldnt match the actual ptr alignment.</p>



<a name="234033509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033509">(Apr 11 2021 at 10:16)</a>:</h4>
<p>why would there be a mismatch?</p>



<a name="234033515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033515">(Apr 11 2021 at 10:17)</a>:</h4>
<p>the alignment in the place would just be the actual alignment of the pointer</p>



<a name="234033516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033516">(Apr 11 2021 at 10:17)</a>:</h4>
<p>(IOW, the alignment field of a "place result" would actually be important. currently, it could technically be removed from miri. I kept it in because I figured we'd eventually change the rules.^^)</p>



<a name="234033526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033526">(Apr 11 2021 at 10:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234033515">said</a>:</p>
<blockquote>
<p>the alignment in the place would just be the actual alignment of the pointer</p>
</blockquote>
<p>no</p>



<a name="234033530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033530">(Apr 11 2021 at 10:17)</a>:</h4>
<p>the alignment in the place created by <code>*</code> <em>needs</em> to be the alignment given be the type</p>



<a name="234033535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033535">(Apr 11 2021 at 10:17)</a>:</h4>
<p>this is required for the way we ceate LLVM IR to be correct</p>



<a name="234033542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033542">(Apr 11 2021 at 10:17)</a>:</h4>
<p>basically, the alignment must be statically known</p>



<a name="234033548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033548">(Apr 11 2021 at 10:17)</a>:</h4>
<p>and then the LLVM backend puts that static value into the IR</p>



<a name="234033591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033591">(Apr 11 2021 at 10:18)</a>:</h4>
<p>Ah right, that's one of the things that would need to change</p>



<a name="234033600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033600">(Apr 11 2021 at 10:18)</a>:</h4>
<p>we can't use plain GEPi here</p>



<a name="234033609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033609">(Apr 11 2021 at 10:18)</a>:</h4>
<p>GEPi is fine with misaligned things</p>



<a name="234033611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033611">(Apr 11 2021 at 10:18)</a>:</h4>
<p><code>load (align=8)</code> is not</p>



<a name="234033627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033627">(Apr 11 2021 at 10:18)</a>:</h4>
<p>The load (at the <code>place2value</code>) needs to be aligned</p>



<a name="234033632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033632">(Apr 11 2021 at 10:18)</a>:</h4>
<p>yes</p>



<a name="234033633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033633">(Apr 11 2021 at 10:19)</a>:</h4>
<p>but the intermediate place ops don't</p>



<a name="234033641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033641">(Apr 11 2021 at 10:19)</a>:</h4>
<p>the alignment in the "place result" is for the load</p>



<a name="234033643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033643">(Apr 11 2021 at 10:19)</a>:</h4>
<p>nor the original <code>*ptr</code> place creation</p>



<a name="234033652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033652">(Apr 11 2021 at 10:19)</a>:</h4>
<p>the UB rule for <code>place2value</code> is: the ptr in the place must be aligned to the alginment in the place; if yes, proceed with memory access"</p>



<a name="234033661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033661">(Apr 11 2021 at 10:19)</a>:</h4>
<p>that is <em>the only reason</em> this alignment field in a place even exists</p>



<a name="234033713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033713">(Apr 11 2021 at 10:20)</a>:</h4>
<p>and for that to make sense, a <code>*</code> needs to use the alignment of the type when computing the "place result"</p>



<a name="234033714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033714">(Apr 11 2021 at 10:20)</a>:</h4>
<p>I think there needs to be another variant on <code>place2value</code> for unaligned loads though?</p>



<a name="234033718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033718">(Apr 11 2021 at 10:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234033714">said</a>:</p>
<blockquote>
<p>I think there needs to be another variant on <code>place2value</code> for unaligned loads though?</p>
</blockquote>
<p>no</p>



<a name="234033742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033742">(Apr 11 2021 at 10:20)</a>:</h4>
<p>Otherwise I don't understand how <code>let x = packed_struct.field;</code> works today</p>



<a name="234033744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033744">(Apr 11 2021 at 10:20)</a>:</h4>
<p>alignment is initialized to the type alignment on <code>*</code></p>



<a name="234033805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033805">(Apr 11 2021 at 10:21)</a>:</h4>
<p>and then the semantics of a "place field projection" (<code>Place&lt;Struct&gt; → Place&lt;Field&gt;</code>) is as follows:</p>
<ul>
<li>the resulting ptr is just <code>ptr_offset_inbounds(input.ptr, field_offset)</code></li>
<li>the resulting alignment is the input alignment restricted to the offset of the field in the struct</li>
</ul>



<a name="234033886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033886">(Apr 11 2021 at 10:23)</a>:</h4>
<p>the latter happens <a href="https://github.com/rust-lang/rust/blob/ba6275b6a9fc05fd5d93220e9a67fe64d663cb62/compiler/rustc_mir/src/interpret/place.rs#L180">here</a></p>



<a name="234033888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033888">(Apr 11 2021 at 10:23)</a>:</h4>
<p>So the way I'm envisioning this, the compiler does an analysis at the MIR stage to see whether the <code>*</code> -&gt; place ops -&gt; load path offsets by a multiple of the load type's alignment, and generates an aligned load operation; if it doesn't know the alignment of the pointer or the offset is unaligned then it generates an unaligned load operation. Then the dynamic semantics don't have to carry around alignment as extra state</p>



<a name="234033904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033904">(Apr 11 2021 at 10:23)</a>:</h4>
<p>the former is idneed what the compiler does when generating LLVM IR. but in no way does that entail the latter.</p>



<a name="234033925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033925">(Apr 11 2021 at 10:24)</a>:</h4>
<p>such an analysis would make the dynamic semantics non-compositional</p>



<a name="234033946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033946">(Apr 11 2021 at 10:24)</a>:</h4>
<p>surely we dont want that^^</p>



<a name="234033966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033966">(Apr 11 2021 at 10:24)</a>:</h4>
<p>The dynamic semantics would say that place results are just pointers, and an aligned load asserts alignment of the pointer that was provided</p>



<a name="234033981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033981">(Apr 11 2021 at 10:25)</a>:</h4>
<p>it would have no idea what alignment to assert</p>



<a name="234033986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033986">(Apr 11 2021 at 10:25)</a>:</h4>
<p>the type being loaded</p>



<a name="234033995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033995">(Apr 11 2021 at 10:25)</a>:</h4>
<p>please describe the semantics of <code>place2value</code> if no alignment information is available in the place</p>



<a name="234033996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234033996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234033996">(Apr 11 2021 at 10:25)</a>:</h4>
<p>that is wrong</p>



<a name="234034001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034001">(Apr 11 2021 at 10:25)</a>:</h4>
<p>Oh!</p>



<a name="234034002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034002">(Apr 11 2021 at 10:25)</a>:</h4>
<p>it doesnt account for packed fields correctly</p>



<a name="234034008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034008">(Apr 11 2021 at 10:25)</a>:</h4>
<p>Oh wait that's still okay, you can bake the alignment into the operation</p>



<a name="234034009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034009">(Apr 11 2021 at 10:25)</a>:</h4>
<p>no it's not there</p>



<a name="234034019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034019">(Apr 11 2021 at 10:26)</a>:</h4>
<p>the operation is <code>place2value</code></p>



<a name="234034050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034050">(Apr 11 2021 at 10:26)</a>:</h4>
<p>it has a <code>Place&lt;i32&gt;</code> to work with, for example</p>



<a name="234034059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034059">(Apr 11 2021 at 10:26)</a>:</h4>
<p>it has <em>no clue</em> if that i32 is in a packed struct or not</p>



<a name="234034068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034068">(Apr 11 2021 at 10:26)</a>:</h4>
<p>and it doesn't know <code>align_of&lt;i32&gt;</code>?</p>



<a name="234034070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034070">(Apr 11 2021 at 10:26)</a>:</h4>
<p>it does but that's useless information</p>



<a name="234034075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034075">(Apr 11 2021 at 10:26)</a>:</h4>
<p>it's loading into a value of type i32?</p>



<a name="234034076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034076">(Apr 11 2021 at 10:26)</a>:</h4>
<p>this place could be the result of computing <code>packed_struct.field</code></p>



<a name="234034079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034079">(Apr 11 2021 at 10:26)</a>:</h4>
<p><code>field</code> has type<code>i32</code></p>



<a name="234034088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034088">(Apr 11 2021 at 10:27)</a>:</h4>
<p>so that place expression denotes a <code>Place&lt;i32&gt;</code></p>



<a name="234034095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034095">(Apr 11 2021 at 10:27)</a>:</h4>
<p>but asserting alignment 4  would be wrong</p>



<a name="234034099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034099">(Apr 11 2021 at 10:27)</a>:</h4>
<p>why?</p>



<a name="234034102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034102">(Apr 11 2021 at 10:27)</a>:</h4>
<p>because it's a packed struct...?</p>



<a name="234034114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034114">(Apr 11 2021 at 10:27)</a>:</h4>
<p>That's what an <em>aligned</em> load would do</p>



<a name="234034118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034118">(Apr 11 2021 at 10:27)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">packed_struct</span><span class="p">.</span><span class="n">field</span><span class="p">;</span><span class="w"></span>
<span class="c1">// is sugar for</span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">place2value</span><span class="p">(</span><span class="n">packed_struct</span><span class="p">.</span><span class="n">field</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="234034125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034125">(Apr 11 2021 at 10:28)</a>:</h4>
<p>there are no aligned and unaligned loads</p>



<a name="234034160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034160">(Apr 11 2021 at 10:28)</a>:</h4>
<p>there is just <code>place2value</code></p>



<a name="234034170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034170">(Apr 11 2021 at 10:28)</a>:</h4>
<p>(in the subset of the language we are considering here)</p>



<a name="234034188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034188">(Apr 11 2021 at 10:28)</a>:</h4>
<p>Okay, so we're back at MIR selection now. In that case, we have to keep offset state and deduce whether we can make the place2value aligned at the point of generation</p>



<a name="234034208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034208">(Apr 11 2021 at 10:29)</a>:</h4>
<p>note that "aligned" is not a <code>bool</code> here</p>



<a name="234034209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034209">(Apr 11 2021 at 10:29)</a>:</h4>
<p>It is possible to just always make it unaligned, I think, and make things aligned as an optimization pass</p>



<a name="234034212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034212">(Apr 11 2021 at 10:29)</a>:</h4>
<p>there is such a think as <code>#[repr(packed(2))]</code></p>



<a name="234034216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034216">(Apr 11 2021 at 10:29)</a>:</h4>
<p>which would make an <code>i32</code> field 2-aligned</p>



<a name="234034276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034276">(Apr 11 2021 at 10:30)</a>:</h4>
<p>true, I'm simplifying here, but I don't think that makes a major difference</p>



<a name="234034298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034298">(Apr 11 2021 at 10:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234034209">said</a>:</p>
<blockquote>
<p>It is possible to just always make it unaligned, I think, and make things aligned as an optimization pass</p>
</blockquote>
<p>this is possible under the current UB rules. it is not possible for your proposed UB rules.<br>
(assuming we want to keep the same LLVM lowering.)</p>



<a name="234034314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034314">(Apr 11 2021 at 10:30)</a>:</h4>
<p>that's what I said earlier: currently, the <code>alignment</code> field in Miri is redundant</p>



<a name="234034326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034326">(Apr 11 2021 at 10:31)</a>:</h4>
<p>but it is redundant only because <code>*ptr</code> is UB on misaligned ptrs</p>



<a name="234034341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034341">(Apr 11 2021 at 10:31)</a>:</h4>
<blockquote>
<p>it is not possible for your proposed UB rules.</p>
</blockquote>
<p>I assume you say that because adding aligned load ops would "add UB"?</p>



<a name="234034362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034362">(Apr 11 2021 at 10:31)</a>:</h4>
<p>The idea is to do an analysis on the place expression to determine that no UB would be introduced before making it aligned</p>



<a name="234034411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034411">(Apr 11 2021 at 10:32)</a>:</h4>
<p>you could certainly still make some of the loads aligned</p>



<a name="234034425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034425">(Apr 11 2021 at 10:32)</a>:</h4>
<p>but e.g. not this one</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">x</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">i32</span> <span class="p">{</span><span class="w"> </span><span class="o">*</span><span class="n">x</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="234034437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034437">(Apr 11 2021 at 10:32)</a>:</h4>
<p>so, at this point you are not just proposing to change the UB rules, or the lowering of address arithmetic, but also the lowering of loads</p>



<a name="234034491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034491">(Apr 11 2021 at 10:33)</a>:</h4>
<p>I'm not necessarily opposed to that, but I am opposed to moving goalposts^^</p>



<a name="234034499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034499">(Apr 11 2021 at 10:34)</a>:</h4>
<p>That's a good example. I want to say yes that's intentional</p>



<a name="234034551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034551">(Apr 11 2021 at 10:34)</a>:</h4>
<p>you started out saying one could get rid of the algnment field in the op.sem and replace it by an optimization; now you are saying we can <em>not</em> do that unless we also change how we compile our code</p>



<a name="234034556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034556">(Apr 11 2021 at 10:34)</a>:</h4>
<p>If you really want it to be aligned you would have to write something like <code>*&amp;*x</code></p>



<a name="234034632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034632">(Apr 11 2021 at 10:35)</a>:</h4>
<p>Well some code lowering has to be changed to make <code>addr_of!((*NULL).field)</code> work, since as you said LLVM is already assuming this is UB</p>



<a name="234034634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034634">(Apr 11 2021 at 10:35)</a>:</h4>
<p>I get the feeling the "get rid of places" proposal also has moved enough that it's not actually getting rid of places any more but is more like a variant of <a href="#narrow/stream/213817-t-lang/topic/Alignment.20and.20raw.20pointer.20deref/near/233450446">what I posted recently</a></p>



<a name="234034657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034657">(Apr 11 2021 at 10:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234034632">said</a>:</p>
<blockquote>
<p>Well some code lowering has to be changed to make <code>addr_of!((*NULL).field)</code> work, since as you said LLVM is already assuming this is UB</p>
</blockquote>
<p>lowering of place offsets has to change for this. but not lowering of <code>place2value</code>.</p>



<a name="234034839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034839">(Apr 11 2021 at 10:38)</a>:</h4>
<p>anyway I need to get going now. I hope next time we can be more clear from the start about what the <em>goals</em> are of a given proposal, and which problems it is trying to solve. if one starts with the proposed solution without giving that context, it is really hard to understand why anything makes any sense.^^</p>



<a name="234034962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034962">(Apr 11 2021 at 10:40)</a>:</h4>
<p>The goal of this proposal is to have simple rules about how places work, ideally defining as much as we can. I will have to think more about your points about unaligned places and place2value</p>



<a name="234034997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234034997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234034997">(Apr 11 2021 at 10:42)</a>:</h4>
<p>in particular, <code>addr_of!((*ptr).field.subfield)</code> should not need to assume alignment or dereferenceable</p>



<a name="234035686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234035686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234035686">(Apr 11 2021 at 10:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234034962">said</a>:</p>
<blockquote>
<p>The goal of this proposal is to have simple rules about how places work, ideally defining as much as we can. I will have to think more about your points about unaligned places and place2value</p>
</blockquote>
<p>so what about <a href="#narrow/stream/213817-t-lang/topic/Alignment.20and.20raw.20pointer.20deref/near/233450446">these rules</a>? I keep mentioning them (including linking to them during our discussion today multiple times) and I do not think you have commented on them yet.</p>



<a name="234035697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234035697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234035697">(Apr 11 2021 at 10:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234034997">said</a>:</p>
<blockquote>
<p>in particular, <code>addr_of!((*ptr).field.subfield)</code> should not need to assume alignment or dereferenceable</p>
</blockquote>
<p>this is achieved by the rules I linked above</p>



<a name="234035730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234035730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234035730">(Apr 11 2021 at 10:55)</a>:</h4>
<p>(those rules do not go into the packed struct situation; but the existing <code>alignment</code> field of a "place result" in Miri is sufficient to handle that)</p>



<a name="234035925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234035925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234035925">(Apr 11 2021 at 10:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234034634">said</a>:</p>
<blockquote>
<p>I get the feeling the "get rid of places" proposal also has moved enough that it's not actually getting rid of places any more but is more like a variant of <a href="#narrow/stream/213817-t-lang/topic/Alignment.20and.20raw.20pointer.20deref/near/233450446">what I posted recently</a></p>
</blockquote>
<p>Looking at that again, I think I agree with all of it, and this matches a version of my proposal before our conversation. But as you yourself have pointed out, it's not refined enough to handle packed places properly; <code>let x = packed_struct.field;</code> would fail if we assert that it is 4 byte aligned. But given your later comments, I think the way you intend to fill the gap is by associating an "environmental alignment" value to place results, with the following rules:</p>
<ul>
<li>creating a place from a ptr/ref (via <code>*</code>) creates a place with environmental alignment from the type</li>
<li>offsetting a place via (<code>place.field</code>) creates a place with environmental alignment <code>min(N, P, T)</code> where <code>N</code> is the <code>packed(N)</code> value of the struct, <code>P</code> is the environmental alignment of the place and <code>T</code> is the alignment of the type</li>
<li>loading or writing to a place asserts that the place's pointer is aligned to its environmental alignment</li>
</ul>
<p>(I don't want to call it the place's alignment because the place need not actually be aligned to its environmental alignment; it only represents the alignment we are allowed to assume based on the structure of the place expression.)</p>



<a name="234036039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036039">(Apr 11 2021 at 11:00)</a>:</h4>
<blockquote>
<p>offsetting a place via (place.field) creates a place with environmental alignment min(N, max(P, T)) where N is the packed(N) value of the struct, P is the environmental alignment of the place and T is the alignment of the type</p>
</blockquote>
<p>not exactly; the new "env-align" is given by <code>old_align.restrict_for_offset(offset)</code>. which is basically <code>min(old, off_align)</code> where <code>off_align</code> is the largest power of 2 that is a divisor of <code>offset</code>.</p>



<a name="234036097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036097">(Apr 11 2021 at 11:01)</a>:</h4>
<p>but this is probably equivalent</p>



<a name="234036148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036148">(Apr 11 2021 at 11:02)</a>:</h4>
<p>except, shouldnt the inner <code>max</code> in your term be <code>min</code>?</p>



<a name="234036156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036156">(Apr 11 2021 at 11:02)</a>:</h4>
<p>How do you feel about one of the litmus tests from above though?</p>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/233999829">said</a>:</p>
<blockquote>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[repr(packed)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Packed</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">5</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="kt">u32</span> <span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="nc">Packed</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">Foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">b</span><span class="p">.</span><span class="n">b</span><span class="p">;</span><span class="w"> </span><span class="c1">// (1) should this be safe?</span>
</code></pre></div><br>
</p>
</blockquote>



<a name="234036216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036216">(Apr 11 2021 at 11:03)</a>:</h4>
<p>I think these rules make that code UB</p>



<a name="234036220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036220">(Apr 11 2021 at 11:03)</a>:</h4>
<p>whether something is "safe" isnt part of our discussion; are you asking of it is UB?</p>



<a name="234036266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036266">(Apr 11 2021 at 11:04)</a>:</h4>
<p>it is not, according to the rules I proposed and with the existing env-align handling in Miri</p>



<a name="234036292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036292">(Apr 11 2021 at 11:04)</a>:</h4>
<p><code>x</code>'s env-align will be 1</p>



<a name="234036298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036298">(Apr 11 2021 at 11:04)</a>:</h4>
<p><code>x.b</code> will still be 1</p>



<a name="234036300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036300">(Apr 11 2021 at 11:04)</a>:</h4>
<p>and <code>x.b.b</code> likewise</p>



<a name="234036303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036303">(Apr 11 2021 at 11:04)</a>:</h4>
<p>Oh I guess it goes the other way, we're underapproximating the alignment</p>



<a name="234036323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036323">(Apr 11 2021 at 11:05)</a>:</h4>
<p>so we're required to do an unaligned load even though it's aligned</p>



<a name="234036333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036333">(Apr 11 2021 at 11:05)</a>:</h4>
<p>it's not aligned though</p>



<a name="234036340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036340">(Apr 11 2021 at 11:05)</a>:</h4>
<p><code>x</code> might be sitting at address 1337</p>



<a name="234036360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036360">(Apr 11 2021 at 11:05)</a>:</h4>
<p>Oops, <code>Foo</code> is supposed to be <code>align(4)</code></p>



<a name="234036366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036366">(Apr 11 2021 at 11:06)</a>:</h4>
<p>stick a <code>u32</code> in there</p>



<a name="234036406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036406">(Apr 11 2021 at 11:06)</a>:</h4>
<p>ah^^</p>



<a name="234036417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036417">(Apr 11 2021 at 11:06)</a>:</h4>
<p>well yeah that's like having a <code>(u32, u8)</code></p>



<a name="234036426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036426">(Apr 11 2021 at 11:06)</a>:</h4>
<p>well actually for <code>(u32, u8)</code> my rules will emit a 4-aligned load</p>



<a name="234036430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036430">(Apr 11 2021 at 11:06)</a>:</h4>
<p>to the 2nd field</p>



<a name="234036438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036438">(Apr 11 2021 at 11:06)</a>:</h4>
<p>because only the offset of the field matters, not the alignment of the type of the field</p>



<a name="234036441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036441">(Apr 11 2021 at 11:07)</a>:</h4>
<p>like this</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[repr(packed)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Packed</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">5</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="kt">u32</span> <span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="p">],</span><span class="w"> </span><span class="n">b</span>: <span class="nc">Packed</span><span class="p">,</span><span class="w"> </span><span class="n">c</span>: <span class="kt">u32</span> <span class="p">}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">Foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">b</span><span class="p">.</span><span class="n">b</span><span class="p">;</span><span class="w"> </span><span class="c1">// can this be an aligned load?</span>
</code></pre></div>



<a name="234036477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036477">(Apr 11 2021 at 11:07)</a>:</h4>
<p>make <code>Foo</code> <code>repr(C)</code> and it <em>can</em> be an aligned load as part of an optimization, but our lowering scheme won't naively do that</p>



<a name="234036546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036546">(Apr 11 2021 at 11:08)</a>:</h4>
<p>but... since we agree the load is not UB, that also seems irrelevant :)</p>



<a name="234036552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036552">(Apr 11 2021 at 11:08)</a>:</h4>
<p>there'll always be aligned loads that we do not mark as such</p>



<a name="234036553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036553">(Apr 11 2021 at 11:08)</a>:</h4>
<p>And I suppose you agree it should be <code>unsafe { } </code> regardless?</p>



<a name="234036563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036563">(Apr 11 2021 at 11:08)</a>:</h4>
<p>eh... this is safe code today^^</p>



<a name="234036564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036564">(Apr 11 2021 at 11:08)</a>:</h4>
<p>it'll just emit a 1-aligned load</p>



<a name="234036598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036598">(Apr 11 2021 at 11:09)</a>:</h4>
<p><code>&amp;x.b.b</code> is not just unsafe but outright forbidden -- and I dont think we should change that</p>



<a name="234036703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036703">(Apr 11 2021 at 11:11)</a>:</h4>
<p>Great, I think we agree then. All this talk of env-aligned pointers makes me wonder whether there is space in the language for under-aligned references that can be used here</p>



<a name="234036713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036713">(Apr 11 2021 at 11:11)</a>:</h4>
<p>but I guess that's a conversation for another day</p>



<a name="234036900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234036900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234036900">(Apr 11 2021 at 11:15)</a>:</h4>
<p>:)</p>



<a name="234038595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234038595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234038595">(Apr 11 2021 at 11:45)</a>:</h4>
<p>By the way, now that I have a better idea about how "env-align" works, I think I can better describe the MIR lowering pass to move env-align out of the dynamic semantics and into the operation.</p>
<ul>
<li>Env-align is a property statically associated to place expressions in MIR, with rules essentially the same as those given above:<ul>
<li>The env-align of <code>*ptr</code> or <code>*ref</code> of type <code>T</code> is the alignment of <code>T</code>.</li>
<li>The env-align of <code>place.field</code> is the env-align of place restricted for the offset of <code>field</code> (using <code>restrict_for_offset</code>).</li>
</ul>
</li>
<li>When constructing <code>place2value</code> of a place expression <code>place</code>, we get the env-align <code>n</code> of the place, and put the operation <code>place2value(place: T, align n)</code> in the MIR.</li>
</ul>
<p>In the dynamic semantics:</p>
<ul>
<li>Place results are (newtyped) pointers.</li>
<li>The expression <code>place2value(place: T, align n)</code> evaluates <code>place</code> to a result (a pointer), and then loads the pointer at type <code>T</code>, using the alignment <code>n</code>. This operation is UB unless <code>place</code> is aligned to <code>n</code>, and dereferenceable with memory valid at <code>T</code>.</li>
</ul>
<p>I think the semantics can work either way (I assert that they are equivalent), but since env-align is a static property (it follows from the structure of a place expression) it makes a bit more sense to me to not put it in the dynamic semantics as ghost state when it's not needed. (Also, this lowering makes it really easy to see when it is safe to codegen an aligned load.)</p>



<a name="234038923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234038923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234038923">(Apr 11 2021 at 11:50)</a>:</h4>
<p>I agree this would be possible. But the lowering also means that we dont end up having a purely compositional semantics <em>on MIR itself</em>.</p>



<a name="234038928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234038928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234038928">(Apr 11 2021 at 11:50)</a>:</h4>
<p>In particular, we could not use this lowering in Miri.</p>



<a name="234038954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234038954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234038954">(Apr 11 2021 at 11:51)</a>:</h4>
<p>Why is that? If <code>place2value</code> already contains the <code>align</code> field then miri should be able to use it too</p>



<a name="234038959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234038959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234038959">(Apr 11 2021 at 11:51)</a>:</h4>
<p>it doesn't, though^^</p>



<a name="234038978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234038978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234038978">(Apr 11 2021 at 11:52)</a>:</h4>
<p>so let me clarify: to use this approach in Miri we'd have to change the MIR datatypes that are used throughout the compiler</p>



<a name="234039033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039033">(Apr 11 2021 at 11:52)</a>:</h4>
<p>plenty of trade-offs apply there, and I am not sure if this would overall be a good change. MIR is consumed not just by Miri.</p>



<a name="234039036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039036">(Apr 11 2021 at 11:52)</a>:</h4>
<p>Right, this version would actually change the mir datatype</p>



<a name="234039050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039050">(Apr 11 2021 at 11:52)</a>:</h4>
<p>one could view this as sharing some code between Miri and the LLVM backend, by instead doing that work already during MIR building.</p>



<a name="234039054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039054">(Apr 11 2021 at 11:53)</a>:</h4>
<p>for size reasons, you might want to calculate this on the fly, which brings it back to the current version</p>



<a name="234039074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039074">(Apr 11 2021 at 11:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039054">said</a>:</p>
<blockquote>
<p>for size reasons, you might want to calculate this on the fly, which brings it back to the current version</p>
</blockquote>
<p>no that wouldn't work in a compositional way for miri I think</p>



<a name="234039113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039113">(Apr 11 2021 at 11:54)</a>:</h4>
<p>the <code>place2value</code> code has no idea what the original place <em>expression</em> was that it is running on</p>



<a name="234039125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039125">(Apr 11 2021 at 11:54)</a>:</h4>
<p>and the place expression is executed projection-by-projection without knowing any other context</p>



<a name="234039148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039148">(Apr 11 2021 at 11:55)</a>:</h4>
<p>This is like typechecker data, miri can forget most but not all of it</p>



<a name="234039165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039165">(Apr 11 2021 at 11:55)</a>:</h4>
<p>Where is the type stored in a load?</p>



<a name="234039182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039182">(Apr 11 2021 at 11:55)</a>:</h4>
<p>it also sounds rather painful if <em>each and every</em> <code>write</code> call in Miri has to somehow cook up an alignment</p>



<a name="234039245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039245">(Apr 11 2021 at 11:56)</a>:</h4>
<p>that's what miri already has to do though, that's what the alignment field in place results is</p>



<a name="234039254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039254">(Apr 11 2021 at 11:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039165">said</a>:</p>
<blockquote>
<p>Where is the type stored in a load?</p>
</blockquote>
<p>also in the place (<code>PlaceTy</code> is the type we really carry around in miri during evaluation, it's a <code>Place</code> and a <code>TyAndLayout</code>)</p>



<a name="234039272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039272">(Apr 11 2021 at 11:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039245">said</a>:</p>
<blockquote>
<p>that's what miri already has to do though, that's what the alignment field in place results is</p>
</blockquote>
<p>there are many callers of these <code>write</code> methods. none of them worry about env-align as it is entirely handled by the <code>place.rs</code> methods.</p>



<a name="234039281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039281">(Apr 11 2021 at 11:57)</a>:</h4>
<p>the place result or the type of the operation?</p>



<a name="234039286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039286">(Apr 11 2021 at 11:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039281">said</a>:</p>
<blockquote>
<p>the place result or the type of the operation?</p>
</blockquote>
<p>the place type</p>



<a name="234039295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039295">(Apr 11 2021 at 11:57)</a>:</h4>
<p>Can the alignment be stored there too?</p>



<a name="234039357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039357">(Apr 11 2021 at 11:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039295">said</a>:</p>
<blockquote>
<p>Can the alignment be stored there too?</p>
</blockquote>
<p>not sure, maybe</p>



<a name="234039372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039372">(Apr 11 2021 at 11:58)</a>:</h4>
<p>that would basically mean places are typed by a type <code>T</code> and an alignment <code>N</code></p>



<a name="234039394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039394">(Apr 11 2021 at 11:59)</a>:</h4>
<p>at least in the past miri sometimes used the more precise dynamic alignment when dynamically sized types are involved; we'd have to be careful not to do that</p>



<a name="234039479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039479">(Apr 11 2021 at 12:00)</a>:</h4>
<p>Oh that's an interesting example. Dynamically sized types are basically encoding the types at run time, does that mean the alignment also has to be encoded?</p>



<a name="234039504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039504">(Apr 11 2021 at 12:00)</a>:</h4>
<p>the offset of the last field of a struct with an unsized tail is dynamic</p>



<a name="234039512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039512">(Apr 11 2021 at 12:00)</a>:</h4>
<p>it depends on the alignment of the unsized tail</p>



<a name="234039537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039537">(Apr 11 2021 at 12:01)</a>:</h4>
<p>but of course for LLVM codegen we really only care about the best static approximation of that dynamic value</p>



<a name="234039538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039538">(Apr 11 2021 at 12:01)</a>:</h4>
<p>Oh I was thinking of trait objects, now I see what you mean</p>



<a name="234039558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039558">(Apr 11 2021 at 12:01)</a>:</h4>
<p>so one could still make the alginment of a place a static concept</p>



<a name="234039599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039599">(Apr 11 2021 at 12:02)</a>:</h4>
<p>not sure if that would really simplify miri and/or the spec by that much, though</p>



<a name="234039619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039619">(Apr 11 2021 at 12:02)</a>:</h4>
<p>I suspect it would make miri a bit faster</p>



<a name="234039628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039628">(Apr 11 2021 at 12:02)</a>:</h4>
<p>for miri it'd basically just move the field from one struct to another</p>



<a name="234039630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039630">(Apr 11 2021 at 12:02)</a>:</h4>
<p>I dont see how that could possibly make any perf difference</p>



<a name="234039638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039638">(Apr 11 2021 at 12:02)</a>:</h4>
<p>since it means runtime values are a bit smaller and the alignments don't need to be computed all the time</p>



<a name="234039641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039641">(Apr 11 2021 at 12:03)</a>:</h4>
<p>miri doesn't use dependent types to literally have <code>Place&lt;T&gt;</code>^^</p>



<a name="234039684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039684">(Apr 11 2021 at 12:03)</a>:</h4>
<p>so it'd still be all runtime for miri</p>



<a name="234039687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039687">(Apr 11 2021 at 12:03)</a>:</h4>
<p>just moved from <code>Place</code> to <code>PlaceTy</code></p>



<a name="234039693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039693">(Apr 11 2021 at 12:03)</a>:</h4>
<p>Oh, you are computing the Ty at runtime too?</p>



<a name="234039695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039695">(Apr 11 2021 at 12:03)</a>:</h4>
<p>yeah sure... this is an interpreter, what else could we do?</p>



<a name="234039697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039697">(Apr 11 2021 at 12:03)</a>:</h4>
<p>I thought you were just pulling it out of the mir</p>



<a name="234039699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039699">(Apr 11 2021 at 12:04)</a>:</h4>
<p>yes we do</p>



<a name="234039722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039722">(Apr 11 2021 at 12:04)</a>:</h4>
<p>but this is runtime</p>



<a name="234039736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039736">(Apr 11 2021 at 12:04)</a>:</h4>
<p>of miri</p>



<a name="234039751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039751">(Apr 11 2021 at 12:04)</a>:</h4>
<p>it's an interpreter after all^^</p>



<a name="234039765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039765">(Apr 11 2021 at 12:04)</a>:</h4>
<p>right but you can prepare the mir beforehand to have all the types, and then when you go through the loops and such you just grab the type of the operation you are currently executing</p>



<a name="234039795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039795">(Apr 11 2021 at 12:05)</a>:</h4>
<p>so the values themselves don't need to carry types, they are classified by the types</p>



<a name="234039808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039808">(Apr 11 2021 at 12:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039795">said</a>:</p>
<blockquote>
<p>so the values themselves don't need to carry types, they are classified by the types</p>
</blockquote>
<p>Rust doesnt have dependent types nearly as flexible as what we'd need for this^^</p>



<a name="234039855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039855">(Apr 11 2021 at 12:06)</a>:</h4>
<p>I dont know what kind of magic you think we are doing</p>



<a name="234039857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039857">(Apr 11 2021 at 12:06)</a>:</h4>
<p>but I suspect I am describing a rather large change to miri so I'll investigate before making more uneducated comments</p>



<a name="234039878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039878">(Apr 11 2021 at 12:06)</a>:</h4>
<p>but each time Miri executes <code>x.field</code>, it looks in <code>x</code>'s type for the right field, gets the offset, gets its type, ...</p>



<a name="234039896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039896">(Apr 11 2021 at 12:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234039857">said</a>:</p>
<blockquote>
<p>but I suspect I am describing a rather large change to miri so I'll investigate before making more uneducated comments</p>
</blockquote>
<p>I dont know how what you propose could even possibly be done in Rust.^^ that would require full-blown dependent types.</p>



<a name="234039917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039917">(Apr 11 2021 at 12:07)</a>:</h4>
<p>I <em>think</em> I'm not proposing dependent types</p>



<a name="234039980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234039980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234039980">(Apr 11 2021 at 12:08)</a>:</h4>
<p>(That said, Rust gets closer to dependent types every time I look at the const-eval or const-generics groups ^_^)</p>



<a name="234040017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040017">(Apr 11 2021 at 12:08)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Place</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">TY</span>: <span class="nc">Type</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="nc">Align</span><span class="o">&gt;</span><span class="p">{</span><span class="o">..</span><span class="p">.}</span><span class="w"></span>
</code></pre></div>
<p>that's basically dependent types, isn't it? given how complex of a type <code>Type</code> is I doubt this will work any time soon, if ever^^</p>



<a name="234040022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040022">(Apr 11 2021 at 12:08)</a>:</h4>
<p>Yeah I don't mean that</p>



<a name="234040047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040047">(Apr 11 2021 at 12:09)</a>:</h4>
<p>well but then you end up with what we have (if you flatten a bit)</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Place</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">ty</span>: <span class="nc">Type</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">align</span>: <span class="nc">Align</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">ptr</span>: <span class="nc">Pointer</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="c1">// more stuff for unsized places</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="234040054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040054">(Apr 11 2021 at 12:10)</a>:</h4>
<p><code>x.field</code> is a piece of MIR that you have previously prepared for execution. While doing such preparation, you annotate that <code>x.field : T</code>. Then, during interpretation, when you want to know what type <code>x.field</code> is, you say <code>T</code> instead of getting the <code>field</code> member of <code>x</code>'s type</p>



<a name="234040106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040106">(Apr 11 2021 at 12:10)</a>:</h4>
<p>I dont know what you mean by "prepare for execution"</p>



<a name="234040116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040116">(Apr 11 2021 at 12:10)</a>:</h4>
<p>that sounds like a bytecode-based interpreter</p>



<a name="234040119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040119">(Apr 11 2021 at 12:10)</a>:</h4>
<p>which Miri is not</p>



<a name="234040135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040135">(Apr 11 2021 at 12:11)</a>:</h4>
<p>Miri is a pretty naive interpreter just traversing plain MIR</p>



<a name="234040155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040155">(Apr 11 2021 at 12:11)</a>:</h4>
<p>This elaboration data is probably useful for other things too, but it would bloat the MIR a lot so I dunno if it's good to keep around</p>



<a name="234040215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040215">(Apr 11 2021 at 12:12)</a>:</h4>
<p>well, there are certainly many ways Miri could be sped up :)</p>



<a name="234040221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040221">(Apr 11 2021 at 12:12)</a>:</h4>
<p>While you could turn it into bytecode, here I'm just talking about putting more types on things</p>



<a name="234040245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040245">(Apr 11 2021 at 12:13)</a>:</h4>
<p>It's good to know that Miri is not super optimized, I didn't know that</p>



<a name="234040258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040258">(Apr 11 2021 at 12:13)</a>:</h4>
<p>lol^^</p>



<a name="234040263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040263">(Apr 11 2021 at 12:13)</a>:</h4>
<p>if Miri is super anything then it is super slow ;)</p>



<a name="234040269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040269">(Apr 11 2021 at 12:13)</a>:</h4>
<p>I thought all the slowdown was a necessary component of the safety checking</p>



<a name="234040274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040274">(Apr 11 2021 at 12:14)</a>:</h4>
<p>but on the plus side this means the code can be fairly clean</p>



<a name="234040314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040314">(Apr 11 2021 at 12:14)</a>:</h4>
<p>which is also important for this kind of interpreter^^</p>



<a name="234040334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040334">(Apr 11 2021 at 12:14)</a>:</h4>
<p>Hm, sounds like a tale of two interpreters then</p>



<a name="234040339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040339">(Apr 11 2021 at 12:14)</a>:</h4>
<p>I dont even know what it is that makes miri slow (besides stacked borrows and validity checking which add a 10x or more overhead)</p>



<a name="234040376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040376">(Apr 11 2021 at 12:15)</a>:</h4>
<p>Im not epxerienced in using profilers and interpreting their results, and Miri was "fast enough" for my experiments</p>



<a name="234040394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040394">(Apr 11 2021 at 12:16)</a>:</h4>
<p>I wonder how feasible it is to <em>compile</em> miri executables like valgrind</p>



<a name="234040450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040450">(Apr 11 2021 at 12:16)</a>:</h4>
<p>I think getting the speed up would be really useful for folks who are using miri as a UB detector</p>



<a name="234040564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040564">(Apr 11 2021 at 12:18)</a>:</h4>
<p>well, valgrind isnt sound</p>



<a name="234040567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040567">(Apr 11 2021 at 12:18)</a>:</h4>
<p>Ah, but we can do better</p>



<a name="234040569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040569">(Apr 11 2021 at 12:18)</a>:</h4>
<p>ub-san would be the more interesting model to follow</p>



<a name="234040583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040583">(Apr 11 2021 at 12:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/MIR.20without.20places/near/234040567">said</a>:</p>
<blockquote>
<p>Ah, but we can do better</p>
</blockquote>
<p>you cant do better with the valgrind approach</p>



<a name="234040587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040587">(Apr 11 2021 at 12:19)</a>:</h4>
<p>you cant do sound UB detection <em>after</em> running an optimizing compiler on your code</p>



<a name="234040597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040597">(Apr 11 2021 at 12:19)</a>:</h4>
<p>you need to instrument the code already during compilation, ub-san style</p>



<a name="234040672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040672">(Apr 11 2021 at 12:20)</a>:</h4>
<p>As a first pass, I guess you could "just" turn miri into a proc-macro that adds instrumentation to the input code, as though you were just unrolling all the functions in miri</p>



<a name="234040700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040700">(Apr 11 2021 at 12:21)</a>:</h4>
<p>Or I guess that could be expressed as a function MIR -&gt; rust code and then compile the rust code</p>



<a name="234040786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040786">(Apr 11 2021 at 12:22)</a>:</h4>
<p>so no fancy memory managers here, just lots of hopefully inlined and optimized function calls</p>



<a name="234040953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040953">(Apr 11 2021 at 12:25)</a>:</h4>
<p>basically just instantiate Miri with some particular MIR, partially evaluate the heck out of that, and -- done :D</p>



<a name="234040964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MIR%20without%20places/near/234040964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MIR.20without.20places.html#234040964">(Apr 11 2021 at 12:25)</a>:</h4>
<p>the old story: interpreter + partial evaluation = compiler</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>